package com.um.jdy.mp.user.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.um.jdy.mp.user.entity.dto.CodeParams;
import com.um.jdy.mp.user.manager.WXManager;
import com.um.springboot.starter.annotation.RequestJson;
import com.um.springboot.starter.orm.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.Length;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信
 *
 * @author cs
 * 日期 2023/5/23
 * 版权所有 广州优匠科技有限公司
 */
@RestController
@RequestMapping("/api/v1/user/wx")
@Api(tags = "微信")
@Validated
public class WXController {
    @Autowired
    WXManager wxManager;

    /**
     * 微信登录
     *
     * @param codeParams
     * @return
     */
    @ApiOperation(value = "微信登录")
    @PostMapping("/signin")
    public Response signin(@RequestBody CodeParams codeParams) {
        return wxManager.signin(codeParams.getCode());
    }

    /**
     * 微信解绑
     *
     * @return
     */
    @ApiOperation(value = "微信解绑")
    @PostMapping("/unbind")
    @SaCheckLogin
    public Response unbind() {
        wxManager.unbind();
        return Response.success();
    }
}
